home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / Demos / Tools / AppMaker / Examples / pre-built AMReminder / PowerPlant / CAMReminderDoc.cp < prev    next >
Encoding:
Text File  |  1994-11-03  |  5.0 KB  |  217 lines  |  [TEXT/MMCC]

  1. // CAMReminderDoc.cp -- Document methods
  2. // Created 01/01/95 12:01 PM by AppMaker
  3.  
  4. #include "CAMReminderDoc.h"
  5.  
  6. #include "CAMReminderData.h"
  7. #include "CMainWindow.h"
  8.  
  9. #include <LFile.h>
  10. #include <LPlaceHolder.h>
  11. #include <LPrintout.h>
  12. #include <LWindow.h>
  13. #include <UWindows.h>
  14. #include <String_Utils.h>
  15.  
  16. const ResIDT    prto_PrintView        = 201;
  17. const ResIDT    STRx_Untitled        = 128;
  18.  
  19. // ---------------------------------------------------------------------------
  20. //        • CAMReminderDoc - new file
  21. // ---------------------------------------------------------------------------
  22.  
  23. CAMReminderDoc::CAMReminderDoc(
  24.     LCommander    *inSuper)
  25.         : LSingleDoc(inSuper)
  26. {
  27.     mData = new CAMReminderData();
  28.  
  29.     MakeWindows();
  30.  
  31.     NameNewDoc();                // Set name of untitled window
  32. }
  33.  
  34. // ---------------------------------------------------------------------------
  35. //        • CAMReminderDoc - open file
  36. // ---------------------------------------------------------------------------
  37.  
  38. CAMReminderDoc::CAMReminderDoc(
  39.     LCommander    *inSuper,
  40.     FSSpec        *inFileSpec)
  41.         : LSingleDoc(inSuper)
  42. {
  43.     mData = new CAMReminderData(inFileSpec);
  44.  
  45.     MakeWindows();
  46.  
  47.     mWindow->SetDescriptor(inFileSpec->name);
  48.     mIsSpecified = true;
  49. }
  50.  
  51. // ---------------------------------------------------------------------------
  52. //        • ~CAMReminderDoc
  53. // ---------------------------------------------------------------------------
  54. //    Destructor
  55. //
  56.  
  57. CAMReminderDoc::~CAMReminderDoc()
  58. {
  59.     delete mData;
  60. }
  61.  
  62. // ---------------------------------------------------------------------------
  63. //        • MakeWindows
  64. // ---------------------------------------------------------------------------
  65.  
  66. void
  67. CAMReminderDoc::MakeWindows()
  68. {
  69.     mMainWindow = CMainWindow::CreateMainWindow(this, mData);
  70.  
  71.     mWindow = mMainWindow;
  72. }
  73.  
  74. // ---------------------------------------------------------------------------
  75. //        • NameNewDoc
  76. // ---------------------------------------------------------------------------
  77. //    Name a new, untitled document window
  78. //
  79. //    Untitled windows start with "untitled", then "untitled 1",
  80. //    "untitled 2", etc. Old numbers are reused, so there won't be
  81. //    gaps in the numbering.
  82. //
  83. //    This routine uses a STR# resource to store the "untitled" string,
  84. //    which can be localized to different languages. The first string
  85. //    is "untitled" and the second is "untitled " (trailing space),
  86. //    which is used when appending a number to the name.
  87.  
  88. void
  89. CAMReminderDoc::NameNewDoc()
  90. {
  91.         // Start with the default name("untitled")
  92.     Str255    name;
  93.     ::GetIndString(name, STRx_Untitled, 1);
  94.  
  95.     long    num = 0;
  96.     while (UWindows::FindNamedWindow(name) != nil) {
  97.  
  98.             // An existing window has the current name
  99.             // Increment counter and try again
  100.  
  101.         ::GetIndString(name, STRx_Untitled, 2);
  102.         num++;
  103.         Str15    numStr;
  104.         ::NumToString(num, numStr);
  105.         ConcatPStr(name, numStr);
  106.     }
  107.  
  108.     mWindow->SetDescriptor(name);        // Finally, set window title
  109. }
  110.  
  111. // ---------------------------------------------------------------------------
  112. //        • IsModified
  113. // ---------------------------------------------------------------------------
  114. //    Return whether the Document has changed since the last save
  115.  
  116. Boolean
  117. CAMReminderDoc::IsModified()
  118. {
  119.     mIsModified = mData->IsDirty();
  120.  
  121.     return mIsModified;
  122. }
  123.  
  124. // ---------------------------------------------------------------------------
  125. //        • DoAESave
  126. // ---------------------------------------------------------------------------
  127. //    Save Document in the specified file with the specified file type
  128. //
  129. //    If file type is fileType_Default, use the normal file type for
  130. //    this document
  131.  
  132. void
  133. CAMReminderDoc::DoAESave(
  134.     FSSpec    &inFileSpec,
  135.     OSType    inFileType)
  136. {
  137.     mData->DoSaveAs(&inFileSpec);                // Write out data
  138.                                         // Change window name
  139.     mWindow->SetDescriptor(inFileSpec.name);
  140. }
  141.  
  142. //----------
  143. void
  144. CAMReminderDoc::DoSave()
  145. {
  146.     mData->DoSave();
  147. }
  148.  
  149. //----------
  150. void
  151. CAMReminderDoc::DoRevert()
  152. {
  153.     mData->DoRevert();
  154. }
  155.  
  156. // ---------------------------------------------------------------------------
  157. //        • DoPrint
  158. // ---------------------------------------------------------------------------
  159. //    Print the contents of the Document
  160.  
  161. void
  162. CAMReminderDoc::DoPrint()
  163. {
  164.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  165.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  166.                                     thePrintout->FindPaneByID('TBox');
  167. //!    textPlace->InstallOccupant(mTextView, atNone);
  168.  
  169.  
  170.     thePrintout->DoPrintJob();
  171.     delete thePrintout;
  172. }
  173.  
  174. //----------
  175. Boolean
  176. CAMReminderDoc::ObeyCommand(
  177.     CommandT    inCommand,
  178.     void        *ioParam)
  179. {
  180.     Boolean        cmdHandled = true;
  181.  
  182.     switch (inCommand) {
  183.  
  184.     // +++ Add cases here for the commands you handle
  185.     //        Remember to add same cases to FindCommandStatus below
  186.     //        to enable/disable the menu items for the commands
  187.  
  188.     default:
  189.             cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  190.         break;
  191.     }
  192.  
  193.     return cmdHandled;
  194. }
  195.  
  196. //----------
  197. void
  198. CAMReminderDoc::FindCommandStatus(
  199.     CommandT    inCommand,
  200.     Boolean        &outEnabled,
  201.     Boolean        &outUsesMark,
  202.     Char16        &outMark,
  203.     Str255        outName)
  204. {
  205.     outUsesMark = false;
  206.  
  207.     switch (inCommand) {
  208.  
  209.     // +++ Add cases here for the commands you handle
  210.  
  211.     default:
  212.             LSingleDoc::FindCommandStatus(inCommand, outEnabled,
  213.                                             outUsesMark, outMark, outName);
  214.         break;
  215.     }
  216. }
  217.